<template>
  <div class="applicationAssessment">
    <p class="bottons">
      <el-button v-if="!isEdit" @click="submitH3" type="text">
        <i class="el-icon-document"></i>提交H3审批
      </el-button>
      <el-button v-if="!isEdit" @click="cancelAdopt" type="text">
        <i class="el-icon-close"></i>取消通过
      </el-button>
      <el-button v-if="isEdit" @click="ViewProcessTraces" type="text">
        <i class="el-icon-tickets"></i>查看流程痕迹
      </el-button>
      <el-button @click="dialogTableVisible = true" type="text">
        <i class="el-icon-printer"></i>附件
      </el-button>
      <el-button v-if="isEdit" @click="cancelAdopt" type="text">
        <i class="el-icon-close"></i>关闭
      </el-button>
    </p>
    <h1>返还款付款申请审批</h1>
    <table>
      <tr class="tableTitle">
        <td colspan="4">基本信息</td>
      </tr>
      <tr>
        <td>发起人</td>
        <td>{{info.creatorName}}</td>
        <td>发起时间</td>
        <td>{{creatorTime}}</td>
      </tr>
      <tr>
        <td>发起组织名称</td>
        <td>{{info.paymentName}}</td>
        <td>付款审批单号</td>
        <td>{{info.code}}</td>
      </tr>
      <tr>
        <td>付款审批名称</td>
        <td colspan="3">{{info.remark}}</td>
      </tr>
      <tr class="tableTitle">
        <td colspan="4">付款审批概述</td>
      </tr>
      <tr>
        <td>审批事项</td>
        <td>{{info.mattersApproval}}</td>
        <td>付款类型</td>
        <td>{{paymentType}}</td>
      </tr>
      <tr>
        <td>前置条件</td>
        <td colspan="3">
          <pre v-html="info.precondition"></pre>
        </td>
      </tr>
      <tr>
        <td>流程事项编码</td>
        <td colspan="3">{{info.flowCode}}</td>
      </tr>
      <tr>
        <td>付款方</td>
        <td>{{info.paymentName}}</td>
        <td>收款方</td>
        <td>{{info.receiveName}}</td>
      </tr>
      <tr>
        <td>付款方开户支行</td>
        <td>{{info.paymentBankBranch}}</td>
        <td>收款方开户支行</td>
        <td>{{info.receiveBankBranch}}</td>
      </tr>
      <tr>
        <td>付款账号</td>
        <td>{{info.paymentAccount}}</td>
        <td>收款账号</td>
        <td>{{info.receiveAccount}}</td>
      </tr>
      <tr>
        <td>本次请款含税金额</td>
        <td>{{info.payAmount}}</td>
        <td>批复含税金额</td>
        <td>{{info.realAmount}}</td>
      </tr>
      <tr>
        <td>票据方式</td>
        <td>{{billType}}</td>
        <td>计税方式</td>
        <td>{{info.taxType === 1 ? '一般' : '简易'}}</td>
      </tr>
      <tr>
        <td>经办人</td>
        <td>{{info.creatorName}}</td>
        <td>联系电话</td>
        <td>{{info.creatorMobile}}</td>
      </tr>
      <tr class="tableTitle">
        <td colspan="4">审批意见</td>
      </tr>
      <tr style="height:60px" v-for="item in logList" :key="item.id">
        <td v-if="item.oprationFlag == 0">经办人</td>
        <td v-else>审批人</td>
        <td colspan="3" class="approval">
          <span>{{item.content ? item.content : '无'}}</span>
          <span>{{item.userName}}</span>
          <span>{{item.userRole}}</span>
          <span>{{auditTime(item.auditTime)}}</span>
        </td>
      </tr>
    </table>
    <el-dialog :visible.sync="dialogTableVisible">
      <el-table border :data="fileList">
        <el-table-column property="name" label="文件名"></el-table-column>
        <el-table-column property="createName" label="创建人"></el-table-column>
        <el-table-column property="createTime" :formatter="createTime" label="上传时间"></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import utils from "@/common/utils";
import api from "@/api/apiPath";
export default {
  name: "h3ViewProcess",
  data() {
    return {
      info: {},
      fileList: [],
      logList: [],
      dialogTableVisible: false,
      workItemId: "",
      instanceId: "",
      isEdit: false
    };
  },
  computed: {
    creatorTime() {
      return utils.getTimeString(this.info.createTime)
    },
    billType() {
      if (this.info.billType === 1) {
        return "增值税专用发票";
      } else if(this.info.billType === 2){
        return "普通发票";
      }else {
        return ''
      }
    },
    paymentType() {
      if(this.info.paymentType === 1) {
        return '通过银企直连付款（对公）'
      }else if(this.info.paymentType === 2) {
        return '通过银企直连付款（对私）'
      }else {
        return '转账'
      }
    }
  },
  created() {
    if (this.$route.query.edit) {
      this.isEdit = false;
    } else {
      this.isEdit = true;
    }
    this.details(this.$route.query.id);
    this.$axios
      .post("/commission/developer/remark/getList", {
        id: this.$route.query.id
      })
      .then(res => {
        this.logList = res;
      });
  },
  methods: {
    createTime(row) {
      return utils.getTimeString(row.createTime);
    },
    auditTime(auditTime) {
      return utils.getTimeString(auditTime);
    },
    details(id) {
      this.$axios
        .post("/commission/developer/getById", { id: id })
        .then(res => {
          this.info = res;
          this.workItemId = res.workItemId;
          this.instanceId = res.instanceId;
          if (res.url) {
            this.fileList = JSON.parse(res.url);
          }
        });
    },
    submitH3() {
      let form = JSON.parse(window.localStorage.getItem("form"));
      this.$axios.post("/commission/developer/add", form).then(res => {
        this.$message({
          type: "success",
          message: "操作成功"
        });
        window.localStorage.removeItem('form');
        this.$router.push("./developerPayment");
      });
    },
    // 查看流程痕迹
    ViewProcessTraces() {
      // 测试t  生产去掉t
      let mobile = JSON.parse(window.localStorage.getItem("cmsUser")).mobile;

      let variable = document.domain;
      let url;
      if (variable == "localhost") {
        url = "http://th3bpm.lifeat.cn:45787";
      }
      if (variable == "ntcms.lifeat.cn") {
        url = "http://th3bpm.lifeat.cn:45787";
      }
      if (variable == "ncms.lifeat.cn") {
        url = "http://h3bpm.lifeat.cn";
      }
      if (variable == "nhcms.lifeat.cn") {
        url = "https://hh3bpm.lifeat.cn:45788";
      }
      let winUrl = `${url}/Portal/#/platform/login?mobile=${mobile}&workItemId=${this.workItemId}&instanceId=${this.instanceId}`;
      window.open(winUrl);
    },
    // 取消通过
    cancelAdopt() {
      if(this.$route.query.edit) {
        this.$router.push("./editPayment");
      }else {
        this.$router.push('./developerPayment');
      }
    }
  }
};
</script>

<style lang="stylus" scoped>
.applicationAssessment {
  position: relative;

  h1 {
    color: #409eff;
    margin: 35px auto;
    text-align: center;
  }

  .bottons {
    position: absolute;
    right: 35px;
    top: 5px;

    i {
      margin-right: 5px;
    }

    el-button {
      margin-right: 15px;
    }
  }

  table {
    font-size: 15px;
    border-collapse: collapse;
    width: 100%;
    margin: 0 auto;

    tr td {
      border: 1px solid #ccc;
      line-height: 40px;
      box-sizing: border-box;
      padding: 0 3px;
      text-align: center;
      width: 25%;
    }

    tr td:nth-child(odd) {
      text-align: right;
      color: #409eff;
    }

    tr td:nth-child(even) {
      text-align: left;
    }

    .tableTitle td {
      text-align: center !important;
      background: #f2f2f2;
      color: #409eff;
      font-weight: bold;
    }

    pre {
      font-family: 'Avenir', Helvetica, Arial, sans-serif;
    }

    .approval span {
      margin-left: 15px;
    }
  }
}
</style>